import json
import sys


def add_dict_count(d, k):
    if k in d:
        d[k] += 1
    else:
        d[k] = 1


def print_dict(d):
    sl = sorted(d.items(), key=lambda it: it[1], reverse=True)
    for sli in sl:
        print("%s(%d) " % (sli[0], sli[1]), end='')
    print()
    print()


file_name = 'gacha-list.json'
if len(sys.argv) > 1:
    file_name = sys.argv[1]
data = json.load(open(file_name, encoding='utf-8'))
data_list = data['result']

role_5_map = {}
role_4_map = {}
weapon_5_map = {}
weapon_4_map = {}
weapon_3_map = {}
total_5_map = {}
total_4_map = {}

for i in range(4):
    for item in data_list[i][1]:
        name = item[1]
        clazz = item[2]
        star = item[3]
        if star == 5:
            add_dict_count(total_5_map, name)
            if clazz == '武器':
                add_dict_count(weapon_5_map, name)
            else:
                add_dict_count(role_5_map, name)
        elif star == 4:
            add_dict_count(total_4_map, name)
            if clazz == '武器':
                add_dict_count(weapon_4_map, name)
            else:
                add_dict_count(role_4_map, name)
        else:
            add_dict_count(weapon_3_map, name)

print('五星角色')
print_dict(role_5_map)
print('五星武器')
print_dict(weapon_5_map)
print('五星总榜')
print_dict(total_5_map)
print('四星角色')
print_dict(role_4_map)
print('四星武器')
print_dict(weapon_4_map)
print('四星总榜')
print_dict(total_4_map)
print('三星榜')
print_dict(weapon_3_map)
